import Taro from '@tarojs/taro'
import { stringify } from 'qs'

const articlePath =
	'https://platform.test.shjinyi.net/trade/mall/announcement/page'
export const getArticleList = async (params?: any) => {
	const queryString = stringify(params)
	return new Promise((resolove, reject) => [
		Taro.request({
			url: `${articlePath}?${queryString}`,
			success(result) {
				resolove(result.data)
			},
			fail(res) {
				reject(res)
			}
		})
	])
}

const kindRootPath = 'https://platform.test.shjinyi.net/system/kind/root'
export const getKindRootNodes = async (params?: any) => {
	return new Promise<{ id: string; name: string }[]>((resolove, reject) => [
		Taro.request({
			url: `${kindRootPath}`,
			success(res) {
				const result = res.data.filter(item =>
					item.memberTypes.includes(params.memberType)
				)
				resolove(result)
			},
			fail(res) {
				reject(res)
			}
		})
	])
}

export const getMemberType = async () => {
	return new Promise<number[]>(resolove => [
		setTimeout(() => {
			resolove([0, 1])
		}, 300)
	]).then(data =>
		data.map(item => ({ text: !!item ? '公司' : '个人', value: item }))
	)
}
